require(['config'],function(){
    require(['jquery','swiper','template','cookie','loadHF'],function($,Swiper,template){
        new Swiper ('.swiper-container', {
            autoplay: {
                pauseOnMouseEnter: true,
                disableOnInteraction: false,
            },
            effect : 'fade',
            loop: true, // 循环模式选项
            
            // 如果需要分页器
            pagination: {
              el: '.swiper-pagination',
              clickable :true,
            },
            
            // 如果需要前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev',
            },
            
          })
          
          $.getJSON("http://rap2api.taobao.org/app/mock/288018/api/hot", 
          function (resData) {
            const products = resData.data;
            template.defaults.imports.mark = value=>{
              return value + "元";
            }
            const html = template("hot-template",{products})
            $("main").append(html);
          }
          );

          //给li绑定事件
          //每一个对象包括如下属性
          
          $('main').on('click',e=>{
            let $li = $(e.target).parents('.turn-to-detail');
            if($li.length==0){
              $li=$(e.target);
            }
            const goods ={
              id:$li.data('id'),
              title:$li.find('.title').html(),
              des:$li.find('.des').html(),
              image:$li.find('.image').attr('src'),
              curPrice:$li.find('.cur').html(),
              orgPrice:$li.find('.org').html(),
			        amount:1
            };


            //将单项数据保存到cookie中
            $.cookie.json = true;
            $.cookie("goodsInfo",goods,{expires:7});
			location.href = `http://localhost:8888/html/detail.html`;
            //将数据保存到Url当中
            /*
				const info = $.cookie('goodsInfo');
				const arrInfo = Object.entries(info);
				const infoUrl = arrInfo.map(item=>{
				return item.join("=");
				})
				const result = infoUrl.join("&");
				location.href=`http://localhost:8888/html/detail.html?${result}`;
            */
          })
          
        
    })

    
})

